/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.GUI.sidepanels;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import view.GUI.LabelReader;

/**
 *
 * @author Jelle
 */
public class PackageItem extends JLabel implements IItem, MouseListener {

    private boolean collapsed;
    private String lblName;
    private JTextArea ta;

    public PackageItem(String lblName) {
        this.setText(" - " + lblName);
        this.lblName = lblName;
        this.setBackground(Color.WHITE);
        this.setOpaque(true);
        Border b = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
        this.setBorder(b);
        this.addMouseListener(this);
        this.setCollapsed(false);
    }

    /**
     * @return the collapsed
     */
    public boolean isCollapsed() {
        return collapsed;
    }

    /**
     * @param collapsed the collapsed to set
     */
    public void setCollapsed(boolean collapsed) {
        this.collapsed = collapsed;
        if (collapsed) {
            this.setToolTipText(LabelReader.getInstance().getString("clickToExpand"));
            this.setText(" + " + lblName);
        } else {
            this.setText(" - " + lblName);
            this.setToolTipText(LabelReader.getInstance().getString("clickToCollapse"));
        }
    }

    /**
     * @return the lblName
     */
    public String getLblName() {
        return lblName;
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        Palette palette = (Palette) getParent();
        for (Component c : palette.getComponents()) {
            if (PaletteItem.class.isAssignableFrom(c.getClass())) {
                PaletteItem pi = (PaletteItem) c;
                if (pi.getPackageName().equals(lblName)) {
                    pi.setVisible(collapsed);
                }
            }
        }
        setCollapsed(!collapsed);
        palette.invalidate();
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    void addInfoPanelRef(JTextArea ta) {
        this.ta = ta;
    }
}
